package licode.unisop.platform.client.vo;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 定义平台认证后返回的值
 *
 * @author WR
 * @since 2016/6/14 17:36
 */
@Data
public class PlatAuthVO implements Serializable {
    private static final long serialVersionUID = 552221663400281513L;

    private String name;
    private String modelToken;
    private String token;
    private String innerToken;

    private String realmId;
    private String platformId;
    private String homeUrl;
    private String ticketUrl;

    private List<PlatformUrl> urls;
    private Map<String, Object> configs;

    public PlatAuthVO() {
        name = "";
        modelToken = "";
        token = "";
        innerToken = "";
        realmId = "";
        platformId = "";
        homeUrl = "";
        ticketUrl = "";
        configs = new HashMap<>();
    }

    public boolean isValid() {
        return token != null && !token.isEmpty();
    }

    public boolean configAsBoolean(String key, boolean def) {
        if (!configs.containsKey(key)) {
            return def;
        }
        return "true".equals(configs.get(key).toString());
    }

    public PlatAuthVO clonePl() {
        PlatAuthVO clonePl = new PlatAuthVO();

        clonePl.modelToken = this.modelToken;
        clonePl.token = this.token;
        clonePl.innerToken = this.innerToken;
        clonePl.name = this.name;
        clonePl.platformId = this.platformId;
        clonePl.homeUrl = this.homeUrl;
        clonePl.ticketUrl = this.ticketUrl;
        clonePl.configs = new HashMap<>(this.configs);

        return clonePl;
    }
}
